package com.gao.mybatis.test;

import com.gao.mybatis.mapper.SQLMapper;
import com.gao.mybatis.pojo.Emp;
import com.gao.mybatis.utils.sqlSessionUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

/**
 * @Projectname SSM
 * @Filename testDynamicSQL
 * @Author an
 * @Data 2022/7/29 22:24
 * @Description TODO
 */
public class testDynamicSQL {

    @Test
    public void testGetEmpByCondition(){
        SqlSession sqlSession = sqlSessionUtil.getSqlSession();
        SQLMapper mapper = sqlSession.getMapper(SQLMapper.class);
        Emp emp = new Emp(null, "张三", 18, null);
//        for (Emp emp1 : mapper.getEmpByCondition(emp)) {
//            System.out.println(emp1);
//        }

        List<Emp> empByCondition = mapper.getEmpByCondition(emp);
        empByCondition.forEach(System.out::println);
    }

    @Test
    public void testGetEmpByChoose(){
        SqlSession sqlSession = sqlSessionUtil.getSqlSession();
        SQLMapper mapper = sqlSession.getMapper(SQLMapper.class);
        Emp emp = new Emp(null, "张三", 18, null);
        List<Emp> empByCondition = mapper.getEmpByChoose(emp);
        empByCondition.forEach(System.out::println);
    }


    @Test
    public void testInsertMoreEmp(){
        SqlSession sqlSession = sqlSessionUtil.getSqlSession();
        SQLMapper mapper = sqlSession.getMapper(SQLMapper.class);
        Emp emp0 = new Emp(null, "小明0", 18, "男");
        Emp emp1 = new Emp(null, "小明1", 18, "男");
        Emp emp2 = new Emp(null, "小明2", 18, "男");
        List<Emp> emps = Arrays.asList(emp0, emp1, emp2);
        mapper.insertMoreEmp(emps);

    }

    @Test
    public void testDeleteMoreEmp(){
        SqlSession sqlSession = sqlSessionUtil.getSqlSession();
        SQLMapper mapper = sqlSession.getMapper(SQLMapper.class);
        Integer[] integers = {11, 12, 13};
        mapper.deleteMoreEmp(integers);
    }

}
